<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    #box{
      width: 100px;
      height: 100px;
      background: #000;
    }
  </style>
</head>
<body>
  <div id="box"></div>

  <script>
    // 创建一个支持冒泡且不能取消的look事件
    let ev = new Event('look', { bubbles: true, cancelable: true })


    let box = document.getElementById("box");
    box.addEventListener("look", (event) => {
      // console.log(event);
      if (event.cancelable) {
        event.preventDefault()
      } else {
        console.log('在box上触发了look事件');
      }
      
    })

    // window.addEventListener('look', () => {
    //   console.log('在window上触发了look事件');
    // })

    box.dispatchEvent(ev) // 在box上发布look事件
  </script>
</body>
</html>